#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct list
{
  struct list* next;
  char name[20];
  int num;
  float price;
};

void add_data(struct list*);
void display(struct list*);

int main()
{
  struct list* head;
  head = malloc(sizeof(struct list));
  head->next = NULL;
  add_data(head);
  display(head);
  return 0;
}

void add_data(struct list* head)
{
  FILE* file = fopen("./1.txt","r");

  struct list* new_node;
  char name[20];
  int num;
  float price;
  while((fscanf(file,"%s %d %f\n",name,&num,&price)) != -1)
  {
    new_node = malloc(sizeof(struct list));
    new_node->next = head->next;
    head->next = new_node;
    strcpy(new_node->name,name);
    new_node->price = price;
    new_node->num = num;
  }

  fclose(file);
}

void display(struct list* head)
{
  if(head->next == NULL)
  {
    printf("empty\n");
    return ;
  }

  struct list* tmp;
  tmp = head->next;
  while(tmp)
  {
    printf("name:%s ",tmp->name);
    printf("num: %d ",tmp->num);
    printf("num: %f ",tmp->price);
    tmp = tmp->next;
    printf("\n");
  }
}
